package com.eling.elcms.travel.webapp.controller;

import com.eling.elcms.core.dao.hibernate.search.SearchCondition;
import com.eling.elcms.core.webapp.controller.BaseFormController;
import com.eling.elcms.core.webapp.controller.Msg;
import com.eling.elcms.core.webapp.spring.ModelFilling;
import com.eling.elcms.travel.model.RuleScope;
import com.eling.elcms.travel.service.IRuleScopeManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class RuleScopeController  extends BaseFormController{
	@Autowired
	private IRuleScopeManager ruleScopeManager;
	
	@RequestMapping("/api/rulescope/save")
    @ResponseBody
	public RuleScope save(@ModelAttribute@ModelFilling RuleScope data){
		return ruleScopeManager.save(data);
	}
	
	@RequestMapping("/api/rulescope/{pkSettlementsRule}/delete")
	@ResponseBody
	public Msg delete(@PathVariable Long pkRuleScope){
		ruleScopeManager.remove(pkRuleScope);
		return new Msg("删除成功");
	}
	
	@RequestMapping("/api/rulescope/query")
    @ResponseBody
	public List<RuleScope> query(@ModelAttribute RuleScope ruleScope){
		return ruleScopeManager.query(ruleScope);
	}
	
	@RequestMapping("/api/rulescope/search*")
	@ResponseBody
	public List<RuleScope> search(@ModelAttribute SearchCondition sc,@ModelAttribute RuleScope ruleScope){
		sc.setQueryCondition(ruleScope);
		return ruleScopeManager.search(sc);
	}
}
